package com.atguigu.eduservice.controller;

import com.atguigu.commonutils.vo.R;
import com.atguigu.commonutils.vo.Result;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduTeacherService;
import com.atguigu.eduservice.vo.TeacherQuery;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-03-18
 */
@RestController
@Api(description = "讲师管理")
@RequestMapping("/eduservice/teacher")
public class EduTeacherController
{
    @Resource
    private EduTeacherService eduTeacherService;

    /**
     * 查询讲师所有数据
     * @return
     */
    @ApiOperation("查询讲师所有数据")
    @GetMapping("findAll")
    public R findAll()
    {
        return eduTeacherService.findAll();
    }

    /**
     * 通过讲师id逻辑删除讲师
     * @param id
     * @return
     */
    @ApiOperation("通过讲师id逻辑删除讲师")
    @DeleteMapping("{id}")
    public R removeById(@ApiParam(name = "id",value = "讲师id",required = true) @PathVariable String id)
    {
        return eduTeacherService.removeById(id);
    }

    /**
     * 分页查询讲师
     * @param current
     * @param limit
     * @return
     */
    @ApiOperation("分页查询讲师")
    @GetMapping("pageTeacher/{current}/{limit}")
    public R pageListTeacher(@PathVariable Long current,
                             @PathVariable Long limit)
    {
        return eduTeacherService.pageListTeacher(current,limit);
    }

    /**
     *  多条件组合查询
     *  把条件值封装到对象（vo）里面，再传递到接口里面
     */
    @ApiOperation("多条件组合查询讲师")
    @PostMapping("pageTeacherCondition/{current}/{limit}")
    public R pageTeacherCondition(@PathVariable Long current,
                                  @PathVariable Long limit,
                                  @ApiParam("查询讲师多条件组合")
                                  @RequestBody(required = false) TeacherQuery teacherQuery)
    {

        return eduTeacherService.pageTeacherCondition(current,limit,teacherQuery);
    }

    /**
     * 添加讲师
     */
    @PostMapping("addTeacher")
    @ApiOperation("添加讲师")
    public R addTeacher(@RequestBody EduTeacher eduTeacher)
    {
        return eduTeacherService.addTeacher(eduTeacher);
    }
}

